<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //冒泡排序
      var arr = [12, 3, 5, 1, 7];
      function popArr(arr) {
        for(var n = 0 ; n < arr.length-1  ;n++){
            for (var i = 0; i < arr.length-(n+1); i++) {
          if (arr[i] > arr[i + 1]) {
            var abc = arr[i];
            arr[i] = arr[i + 1];
            arr[i + 1] = abc;
          }
        }
        }
        return arr;
      }
     
      console.log(popArr(arr));


    //   var arr = [12, 45, 7, 0];
    //   function popArr() {
    //     for (var i = 0; i < arr.length; i++) {
    //       for (var n = 0; n < arr.length; n++) {
    //         if (arr[n] > arr[n + 1]) {
    //           var num = arr[n];
    //           arr[n] = arr[n + 1];
    //           arr[n + 1] = num;
    //         }
    //       }
    //     }
    //     return arr;
    //   }
    //   console.log(popArr(arr));
    </script>
  </body>
</html>
